package com.zengqingfa.designpattern.create.singleton;

/**
 *
 * @fileName: Singleton5
 * @author: zengqf3
 * @date: 2021-4-5 21:00
 * @description: 静态内部类
 */
public class Singleton5 {

    /**
     * 构造函数私有
     */
    private Singleton5() {
    }

    private static class SingletonHolder {
        private static final Singleton5 instance = new Singleton5();
    }

    //获取实例
    public static Singleton5 getInstance() {
        return SingletonHolder.instance;
    }

    public static void main(String[] args) {
        Singleton5 instance1 = Singleton5.getInstance();
        Singleton5 instance2 = Singleton5.getInstance();
        //com.zengqingfa.designpattern.create.singleton.Singleton5@58372a00
        System.out.println(instance1);
        //ture
        System.out.println(instance2 == instance1);
    }
}
